#ifdef KINECT

#include "inc\GUI\kinect\kinectsnapshotsetframe.h"
#include "ui_kinectsnapshotsetframe.h"

KinectSnapshotSetFrame::KinectSnapshotSetFrame(QWidget *parent) :
    QFrame(parent),
    ui(new Ui::KinectSnapshotSetFrame)
{
    ui->setupUi(this);
    _flowLayout = new FlowLayout(ui->snapshots);

    ui->troy->mirror(true);

    connect(ui->takeSnapshot, SIGNAL(clicked()), this, SLOT(requestSnapshot()));
}

KinectSnapshotSetFrame::~KinectSnapshotSetFrame()
{
    delete ui;
}

void KinectSnapshotSetFrame::setPreview(MotionKeyFrame preview) {
    ui->troy->loadKeyFrame(preview);
}

void KinectSnapshotSetFrame::addSnapshot(int id, MotionKeyFrame frame) {
    int frameSize = qFloor(ui->snapshots->width()/(float)100.0)*25;
    int margin = 3;
    int columnCount = 3;

    TroyFrame* troy = new TroyFrame();
    troy->loadKeyFrame(frame);
    troy->setMinimumSize(frameSize, frameSize);
    troy->mirror(true);
    ////qDebug() << "Moving to:" << QPoint(margin + (frameSize + margin) * (_snapshots.size()%columnCount), margin + (frameSize + margin) * qFloor(_snapshots.size()/columnCount));
    //troy->move(margin + (frameSize + margin) * (_snapshots.size()%columnCount), margin + (frameSize + margin) * qFloor(_snapshots.size()/columnCount));
    ////qDebug() << "Size:" << ui->snapshots->size();
    //troy->show();
    //ui->snapshots->setMinimumSize(margin + (frameSize + margin) * columnCount, margin + (frameSize + margin) * (1+qFloor(_snapshots.size()/columnCount)));
    ////qDebug() << "Resize:" << QPoint(margin + (frameSize + margin) * columnCount, margin + (frameSize + margin) * (1+qFloor(_snapshots.size()/columnCount)));
    _flowLayout->addWidget(troy);
    _snapshots.insert(id, troy);
}

void KinectSnapshotSetFrame::deleteSnapshot(int id) {
    if (_snapshots.contains(id)) {
        _snapshots.find(id).value()->deleteLater();
        _snapshots.remove(id);
    }
}

void KinectSnapshotSetFrame::requestSnapshot() {
    emit snapshotRequest();
}


#endif
